package com.learn.greedy;

import java.util.Arrays;
import java.util.Comparator;

/**
 * 给定一个字符串数组，拼接成一个最小的字符串
 */
public class MinStrs {

    public static class MyComparator implements Comparator<String> {

        @Override
        public int compare(String o1, String o2) {
            return (o1 + o2).compareTo(o2 + o1);
        }
    }


    public String getLowestStr(String[] strs) {
        if (strs == null || strs.length == 0) {
            return null;
        }

        Arrays.sort(strs, new MyComparator());
        String res = "";
        for (String str : strs) {
            res = res + str;
        }
        return res;
    }
}
